<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>DOM节点操作</title>
    <style>
      .father {
        width: 300px;
        height: 200px;
        background-color: red;
      }
      .son {
        width: 200px;
        height: 50px;
        background-color: green;
      }
    </style>
  </head>

  <body>
    <div class="father">
      <p class="son">大儿子</p>
    </div>
    <button class="btn">插入一个标签</button>
    <button class="btn1">删掉</button>
    <script>
      // 一、插入操作
      const father = document.querySelector(".father");
      const btn = document.querySelector(".btn");
      btn.addEventListener("click", function () {
        // 创建输入框的DOM对象
        const inp = document.createElement("input");
        // 放入父标签
        // father.append(inp); // 尾部
        father.prepend(inp); // 头部
      });

      // 二、删除操作
      const son = document.querySelector(".son");
      const btn1 = document.querySelector(".btn1");
      btn1.addEventListener("click", function () {
        son.remove();
      });
    </script>
  </body>
</html>
